package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.entity.OrderForm;
import com.wk1un2.service.OrderFormService;
import com.wk1un2.util.Result;

/**
 * 订单控制器
 * 
 * @author Administrator
 *
 */
@Controller
public class OrderFormController {
	@Autowired
	OrderFormService service;

	@RequestMapping("/Backstage/getAllOrderForm")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("of_id") String of_id, @RequestParam("u_name") String u_name, @RequestParam("of_state") String of_state) {

		if (of_id == null || of_id == "") {
			of_id = null;
		}
		if (u_name == null || u_name == "") {
			u_name = null;
		}
		if (of_state == null || of_state == "") {
			of_state = null;
		}
		List<OrderForm> ls = service.getAll((page - 1) * limit, limit, of_id,u_name, of_state);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

//	
	@RequestMapping("/Backstage/addOrderForm")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("of_state"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	޸
	@RequestMapping("/Backstage/updateOrderForm")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("of_id"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	ɾ
	@RequestMapping("/Backstage/deleteOrderForm")
	@ResponseBody
	public Object delete(@RequestParam("of_id") int of_id) {
		System.out.println(of_id);
		int i = service.delete(of_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
	//修改是否发货
		@RequestMapping("/Backstage/updateorderformsendout")
		@ResponseBody
		public Result updateorderformsendout(Integer of_id, Integer of_sendout) {
			service.updateorderformsendout(of_id, of_sendout);
			return Result.ok("0");
		}
}